package study.edumanagesystemspringboot.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.persistence.DiscriminatorValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zouran
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Component
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@DiscriminatorValue("student")
@ToString(callSuper = true)
public class Student extends Person {


    private Double gradeAverage;
    @TableField(exist = false)
    private List<Grade> gradeList = new ArrayList<>();

    /**
     * @return 人物身份
     */
    @Override
    public String getIdentify() {
        return "student";
    }

    public List<Map<String, Object>> getAllGrades() {
        List<Map<String, Object>> maps = new ArrayList<>();
        for (Grade grade : this.gradeList) {
            Map<String, Object> map = new HashMap<>();
            map.put("name", this.getName());
            map.put("courseId", grade.getCourseId());
            map.put("term", grade.getSchoolYear() + "-" + (grade.getSchoolYear() + 1) + (grade.getTerm() == 1 ? "-秋" : "-春"));
            map.put("courseName", grade.getCourse().getCourseName());
            map.put("teacherName", grade.getCourse().getTeacher().getName());
            map.put("score", grade.getScore());
            map.put("gradePoint", grade.getGradePoint());
            map.put("credit", grade.getCourse().getCredit());
            maps.add(map);
        }
        return maps;
    }

    @Override
    public Map<String, Object> accept(Visitor visitor) {
        return visitor.visit(this);
    }
}
